using System;
using System.Windows;
using System.Xml.Serialization;
using MaxAlarm.Common;

namespace MaxAlarm.Core.Settings
{
    [XmlType("alarm")]
    public class AlarmSettingsItem : DependencyObject, ICloneable
    {
        public static readonly DependencyProperty TypeProperty =
            DependencyProperty.Register("Type", typeof (string), typeof (AlarmSettingsItem), new PropertyMetadata(default(string)));

        [XmlAttribute("type")]
        public string Type
        {
            get { return this.SafeGetValue<string>(TypeProperty); }
            set { this.SafeSetValue(TypeProperty, value); }
        }

        public static readonly DependencyProperty ActionProperty =
            DependencyProperty.Register("Action", typeof (AlarmAction), typeof (AlarmSettingsItem), new PropertyMetadata(AlarmAction.Ignore));

        [XmlAttribute("action")]
        public AlarmAction Action
        {
            get { return this.SafeGetValue<AlarmAction>(ActionProperty); }
            set { this.SafeSetValue(ActionProperty, value); }
        }

        public static readonly DependencyProperty LevelProperty =
            DependencyProperty.Register("Level", typeof (AlarmLevel), typeof (AlarmSettingsItem), new PropertyMetadata(AlarmLevel.Info));
        
        [XmlAttribute("level")]
        public AlarmLevel Level
        {
            get { return this.SafeGetValue<AlarmLevel>(LevelProperty); }
            set { this.SafeSetValue(LevelProperty, value); }
        }

        public static readonly DependencyProperty WaitIntervalProperty =
            DependencyProperty.Register("WaitInterval", typeof (int), typeof (AlarmSettingsItem), new PropertyMetadata(default(int)));

        [XmlAttribute("wait-interval")]
        public int WaitInterval
        {
            get { return this.SafeGetValue<int>(WaitIntervalProperty); }
            set { this.SafeSetValue(WaitIntervalProperty, value); }
        }

        public AlarmSettingsItem()
        {
            Type = string.Empty;
            Action = AlarmAction.Ignore;
            Level = AlarmLevel.Info;
            WaitInterval = 1;
        }

        public AlarmSettingsItem(string type)
            : this()
        {
            Type = type;
        }

        public object Clone()
        {
            return new AlarmSettingsItem
                       {
                           Type = Type,
                           Action = Action,
                           Level = Level,
                           WaitInterval = WaitInterval
                       };
        }
    }
}